<template>
	<view class="container">
		<image class="success-icon" src="@/static/ic_bind_success.png" mode="widthFix"></image>
		<view class="title">添加成功</view>
		<view class="tip">您已添加设备成功 {{ second }}S 后将自动进入下一步</view>
		<BaseButton class="btn-wrapper" shape="circle" text="返回" @click="onBack" />
	</view>
</template>

<script>
	import BaseButton from '@/components/base-button/index.vue'
	export default {
		data() {
			return {
				timer: null,
				second: 3,
			};
		},
		components: {
			BaseButton
		},
		onLoad() {
			this.init();
		},
		onUnload() {
			clearInterval(this.timer);
			this.timer = null;
		},
		methods: {
			init() {
				this.timer = setInterval(() => {
					this.second--;
					if(this.second <= 0) {
						clearInterval(this.timer);
						this.timer = null;
						this.goUrl();
					}
				}, 1000)
			},
			onBack() {
				clearInterval(this.timer);
				this.timer = null;
				this.goUrl();
			},
			goUrl() {
				this.$addDeviceService.clear();
				uni.switchTab({
					url:'/pages/oxygen/index'
				})
			}
		}
	}
</script>

<style lang="scss">
	page {
		background-color: #FFFFFF;
	}
	
	.container {
		display: flex;
		flex-direction: column;
		align-items: center;
		margin-top: 300rpx;
		
		.success-icon {
			width: 180rpx;
			margin-bottom: 64rpx;
		}
		
		.title {
			font-family: SourceHanSansCN, SourceHanSansCN;
			font-weight: bold;
			font-size: 55rpx;
			color: #1D1A1A;
			text-align: center;
		}
		
		.tip {
			font-family: SourceHanSansCN, SourceHanSansCN;
			font-weight: 400;
			font-size: 34rpx;
			color: #AFAFAF;
			text-align: center;
			margin-top: 50rpx;
		}
		
		.btn-wrapper {
			position: absolute;
			bottom: 100rpx;
			left: 50%;
			transform: translateX(-50%);
		}
	}
</style>
